
//
//  ExercisesAnswerAnalysisCell.m
//  ShowYork
//
//  Created by hxh on 2020/9/13.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "ExercisesAnswerAnalysisCell.h"

@interface ExercisesAnswerAnalysisCell ()
@property (nonatomic,strong)UILabel *resutSubLb;
@property (nonatomic,strong)UILabel *resultMainLb;
@property (nonatomic,strong)UILabel *analysisTitleLb;
@property (nonatomic,strong)UILabel *analysisContentLb;
@end

@implementation ExercisesAnswerAnalysisCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    self.resultMainLb = [[UILabel alloc]init];
    self.resultMainLb.textColor = C35;
    self.resultMainLb.font = [UIFont boldSystemFontOfSize:18];
    [self.contentView addSubview:self.resultMainLb];
    [self.resultMainLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(16);
        make.left.mas_equalTo(self.contentView).offset(16);
        make.right.mas_equalTo(self.contentView).offset(-16);
    }];
    
    self.resutSubLb = [[UILabel alloc]init];
    self.resutSubLb.textColor = C102;
    self.resutSubLb.font = font(14);
    self.resutSubLb.numberOfLines = 0;
    [self.contentView addSubview:self.resutSubLb];
    [self.resutSubLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(16);
        make.right.mas_equalTo(self.contentView).offset(-16);
        make.top.mas_equalTo(self.resultMainLb.mas_bottom).offset(8);
    }];
    
    self.analysisTitleLb = [[UILabel alloc]init];
    self.analysisTitleLb.textColor = C35;
    self.analysisTitleLb.font = [UIFont boldSystemFontOfSize:18];
    self.analysisTitleLb.text = @"【答案解析】";
    [self.contentView addSubview:self.analysisTitleLb];
    [self.analysisTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.resutSubLb.mas_bottom).offset(24);
        make.left.mas_equalTo(self.contentView).offset(16);
        make.right.mas_equalTo(self.contentView).offset(-16);
    }];
//
    self.analysisContentLb = [[UILabel alloc]init];
    self.analysisContentLb.textColor = C102;
    self.analysisContentLb.numberOfLines = 0;
    self.analysisContentLb.font = font(14);
    [self.contentView addSubview:self.analysisContentLb];
    [self.analysisContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(16);
        make.right.mas_equalTo(self.contentView).offset(-16);
        make.top.mas_equalTo(self.analysisTitleLb.mas_bottom).offset(8);
        make.bottom.mas_equalTo(self.contentView).offset(-37);
    }];
    
}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"ExercisesAnswerAnalysisCell";
    ExercisesAnswerAnalysisCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[ExercisesAnswerAnalysisCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (void)setModel:(ExercieseQuestionItemModel *)model{
    
    _model = model;
    
    if (model.answerItem.content.length == 0) {
        // 是否是主观题
        if (model.type.intValue == 5) {
            self.resultMainLb.text = @"【正确答案】";
            [[HTMLHelper alloc]attributedTextFromHTML:model.correct andCompleteBlock:^(NSMutableAttributedString *content) {
                self.resutSubLb.attributedText = content;
                if (self.updateCorrectCellFrame) {
                    self.updateCorrectCellFrame();
                }
                model.correctAttr = content;
            }];
        }else{
            self.resultMainLb.text = [NSString stringWithFormat:@"【正确答案：%@ 】",model.correct];
            self.resutSubLb.text = @"你未作答";
        }
    }else{
        // 判断是否答案正确
        if (model.answerItem.doRight) {
            self.resultMainLb.text = @"【回答正确 】";
            self.resutSubLb.text = [NSString stringWithFormat:@"作答用时%@秒。",model.answerItem.doTime];
        }else{
            self.resultMainLb.text = [NSString stringWithFormat:@"【正确答案：%@    你的答案：%@ 】",model.correct,model.answerItem.content];
            self.resutSubLb.text = [NSString stringWithFormat:@"回答错误，作答用时%@秒。",model.answerItem.doTime];
        }
    }

    [[HTMLHelper alloc]attributedTextFromHTML:model.analyze andCompleteBlock:^(NSMutableAttributedString *content) {
        self.analysisContentLb.attributedText = content;
        if (self.updateAnlyzeCellFrame) {
            self.updateAnlyzeCellFrame();
        }
        model.analyzeAttr = content;
        
    }];


}

@end
